package com.example.product_practices.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.product_practices.domain.ReplyTb;
import com.example.product_practices.service.IReplyTbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xin.altitude.cms.common.entity.AjaxResult;
import xin.altitude.cms.common.entity.PageEntity;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/replyTb")
public class ReplyTbController {
    @Autowired
    private IReplyTbService replyTbService;

    @GetMapping("/count")
    public AjaxResult count(Integer questionnaireId) {
        return AjaxResult.success(replyTbService.count(new QueryWrapper<ReplyTb>().eq("questionnaire_id",questionnaireId)));
    }
    @GetMapping("/replyinfo")
    public AjaxResult Replyinfobyid(Integer userId,Integer questionnaireId) {
        return AjaxResult.success(replyTbService.replyinfobyid(userId,questionnaireId));
    }
    @GetMapping("/replyallinfo")
    public AjaxResult Replyinfobathid(@RequestParam(required = false) List<Integer> userIds, Integer questionnaireId) {
        Map<Integer, Integer> map=replyTbService.replyinfobath(userIds,questionnaireId);
        return AjaxResult.success(map);
    }
    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity, ReplyTb replyTb) {
        return AjaxResult.success(replyTbService.page(pageEntity.toPage(), Wrappers.lambdaQuery(replyTb)));
    }

    @GetMapping("/list")
    public AjaxResult list(ReplyTb replyTb) {
        return AjaxResult.success(replyTbService.list(Wrappers.lambdaQuery(replyTb)));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody ReplyTb replyTb) {
        return AjaxResult.success(replyTbService.save(replyTb));
    }

    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ReplyTb replyTb) {
        return AjaxResult.success(replyTbService.updateById(replyTb));
    }

    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(replyTbService.removeByIds(Arrays.asList(ids)));
    }

    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(replyTbService.getById(id));
    }
}
